//
//  HDJsonText.m
//  OTIS_MD
//
//  Created by 何达达 on 2017/8/22.
//  Copyright © 2017年 hedada. All rights reserved.
//

#import "HDJsonText.h"
#import "HDSVTModel.h"
#import "HDBaseModel.h"
@implementation HDJsonText
+(NSString *)modelToJsonWithSVT:(HDSVTModel *)model
{
    HDBaseModel *baseModel = [[HDBaseModel alloc]init];
    
    baseModel.LData = [[BaseLdata alloc]init];
    baseModel.LData.LatchedCount = model.Drive.LData.LatchedCount;
    baseModel.LData.CNT_D = model.Drive.LData.CNT_D;
    baseModel.LData.LastTS = model.Drive.LData.LastTS;
    
    baseModel.LData.L = [NSMutableArray array];
    for (int i = 0; i < model.Drive.LData.L.count; i++) {
        BaseL *baseL = [[BaseL alloc]init];
        L *l = model.Drive.LData.L[i];
        baseL.L = l.L;
        baseL.G_CNT = l.G_CNT;
        baseL.Y_CNT = l.Y_CNT;
        baseL.R_CNT = l.R_CNT;
        baseL.Y1 = l.Y1;
        baseL.Y2 = l.Y2;
        baseL.R1 = l.R1;
        baseL.R2 = l.R2;
        baseL.G_CNT_R = l.G_CNT_R;
        baseL.Y_CNT_R = l.Y_CNT_R;
        baseL.R_CNT_R = l.R_CNT_R;
        baseL.Y1_R = l.Y1_R;
        baseL.Y2_R = l.Y2_R;
        baseL.R1_R = l.R1_R;
        baseL.R2_R = l.R2_R;
        [baseModel.LData.L addObject:baseL];
        
    }
    
    baseModel.BData = [[BaseBdata alloc]init];
    baseModel.BData.LatchedCount = model.Drive.BData.LatchedCount;
    baseModel.BData.CNT_D = model.Drive.BData.CNT_D;
    baseModel.BData.LastTS = model.Drive.BData.LastTS;
    
    
    baseModel.BData.Current_info = [[BaseCurrent_Info alloc]init];
    baseModel.BData.Current_info.Runs_SR = model.Drive.BData.Current_info.Runs_SR;
    baseModel.BData.Current_info.Runs_D = model.Drive.BData.Current_info.Runs_D;
    baseModel.BData.Current_info.BL_BS = model.Drive.BData.Current_info.BL_BS;
    baseModel.BData.Current_info.BD_BS = model.Drive.BData.Current_info.BD_BS;
    baseModel.BData.Current_info.BL_BC = model.Drive.BData.Current_info.BL_BC;
    baseModel.BData.Current_info.BD_BC = model.Drive.BData.Current_info.BD_BC;
    baseModel.BData.Current_info.TUP = model.Drive.BData.Current_info.TUP;
    baseModel.BData.Current_info.TDN = model.Drive.BData.Current_info.TDN;
    
    baseModel.BData.BL_BS = [[BaseBl_Bs alloc]init];
    baseModel.BData.BL_BS.Min = model.Drive.BData.BL_BS.Min;
    baseModel.BData.BL_BS.Max = model.Drive.BData.BL_BS.Max;
    baseModel.BData.BL_BS.Ave = model.Drive.BData.BL_BS.Ave;
    baseModel.BData.BL_BS.Min_RAM = model.Drive.BData.BL_BS.Min_RAM;
    baseModel.BData.BL_BS.Max_RAM = model.Drive.BData.BL_BS.Max_RAM;
    baseModel.BData.BL_BS.Ave_RAM = model.Drive.BData.BL_BS.Ave_RAM;
    
    baseModel.BData.BD_BS = [[BaseBd_Bs alloc]init];
    baseModel.BData.BD_BS.Min = model.Drive.BData.BD_BS.Min;
    baseModel.BData.BD_BS.Max = model.Drive.BData.BD_BS.Max;
    baseModel.BData.BD_BS.Ave = model.Drive.BData.BD_BS.Ave;
    baseModel.BData.BD_BS.Min_RAM = model.Drive.BData.BD_BS.Min_RAM;
    baseModel.BData.BD_BS.Max_RAM = model.Drive.BData.BD_BS.Max_RAM;
    baseModel.BData.BD_BS.Ave_RAM = model.Drive.BData.BD_BS.Ave_RAM;
    
    baseModel.BData.BL_CR = [[BaseBl_Cr alloc]init];
    baseModel.BData.BL_CR.Min = model.Drive.BData.BL_CR.Min;
    baseModel.BData.BL_CR.Max = model.Drive.BData.BL_CR.Max;
    baseModel.BData.BL_CR.Ave = model.Drive.BData.BL_CR.Ave;
    baseModel.BData.BL_CR.Min_RAM = model.Drive.BData.BL_CR.Min_RAM;
    baseModel.BData.BL_CR.Max_RAM = model.Drive.BData.BL_CR.Max_RAM;
    baseModel.BData.BL_CR.Ave_RAM = model.Drive.BData.BL_CR.Ave_RAM;
    
    baseModel.BData.BD_CR = [[BaseBd_Cr alloc]init];
    baseModel.BData.BD_CR.Min = model.Drive.BData.BD_CR.Min;
    baseModel.BData.BD_CR.Max = model.Drive.BData.BD_CR.Max;
    baseModel.BData.BD_CR.Ave = model.Drive.BData.BD_CR.Ave;
    baseModel.BData.BD_CR.Min_RAM = model.Drive.BData.BD_CR.Min_RAM;
    baseModel.BData.BD_CR.Max_RAM = model.Drive.BData.BD_CR.Max_RAM;
    baseModel.BData.BD_CR.Ave_RAM = model.Drive.BData.BD_CR.Ave_RAM;
    
    baseModel.BData.Up = [[BaseUp alloc]init];
    baseModel.BData.Up.Min = model.Drive.BData.Up.Min;
    baseModel.BData.Up.Max = model.Drive.BData.Up.Max;
    baseModel.BData.Up.Ave = model.Drive.BData.Up.Ave;
    baseModel.BData.Up.Min_RAM = model.Drive.BData.Up.Min_RAM;
    baseModel.BData.Up.Max_RAM = model.Drive.BData.Up.Max_RAM;
    baseModel.BData.Up.Ave_RAM = model.Drive.BData.Up.Ave_RAM;
    
    baseModel.BData.Down = [[BaseDown alloc]init];
    baseModel.BData.Down.Min = model.Drive.BData.Down.Min;
    baseModel.BData.Down.Max = model.Drive.BData.Down.Max;
    baseModel.BData.Down.Ave = model.Drive.BData.Down.Ave;
    baseModel.BData.Down.Min_RAM = model.Drive.BData.Down.Min_RAM;
    baseModel.BData.Down.Max_RAM = model.Drive.BData.Down.Max_RAM;
    baseModel.BData.Down.Ave_RAM = model.Drive.BData.Down.Ave_RAM;
    
    NSLog(@"%ld",baseModel.LData.L.count );
    //将baseModel 序列化
  
        //输出字典
        NSDictionary *dic = [ModelToJson getObjectData:baseModel];
        NSLog(@"dic==%@", dic);
        //输出json
        NSData *jsonData = [ModelToJson getJSON:baseModel options:NSJSONWritingPrettyPrinted error:nil];
        NSString *jsonText = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
        NSLog(@"jsonText===%@", jsonText);
    
    return jsonText;

   
}
@end
